package com.richapp.launcher.ui.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.richapp.launcher.R;
import com.richapp.launcher.utils.SharePrefenceUtil;

/**
 * Created by wangwei on 2017/4/13.
 */

public class SimplePop extends PopupWindow implements View.OnClickListener {
    private Context context;
    private final EditText et_des;
    private  onOkCallBack onOkCallBack;

    public SimplePop(Context context,onOkCallBack onOkCallBack) {
        this.context = context;
        this.onOkCallBack = onOkCallBack;
        View view = LayoutInflater.from(context).inflate(R.layout.simple_pop, null);
        setContentView(view);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setTouchable(true);
        this.setOutsideTouchable(true);
        this.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x80000000);
        // 弹出窗体的背景
        this.setBackgroundDrawable(dw);

        et_des = (EditText) view.findViewById(R.id.et_des);
        TextView tv_ok = (TextView) view.findViewById(R.id.btn_ok);
        TextView tv_cancel = (TextView) view.findViewById(R.id.btn_cancel);
        tv_cancel.setOnClickListener(this);
        tv_ok.setOnClickListener(this);
        String des = SharePrefenceUtil.getStringValue(context, SharePrefenceUtil.SHAPRE_DESCRIBE_BOX);
        if (!TextUtils.isEmpty(des)) {
            et_des.setText(des);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_ok) {
            SharePrefenceUtil.setStringValue(context, et_des.getText().toString(), SharePrefenceUtil.SHAPRE_DESCRIBE_BOX);
            onOkCallBack.ok(et_des.getText().toString());
            dismiss();
        } else if (v.getId() == R.id.btn_cancel) {
            dismiss();
        }

    }

    public  interface  onOkCallBack{
        void  ok(String s);
    }
}
